﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;

namespace tabwin
{
    public partial class Loader : Form
    {
        public Loader()
        {
            InitializeComponent();
        }

        private void Form2_FormClosed(object sender, FormClosedEventArgs e)
        {
            MoudelCommon.RemoveTab(this.Controls[0].Name);
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            string path = Environment.CurrentDirectory + "\\" + "test.dll";
            Assembly asm = Assembly.LoadFile(path);
            object obj = asm.CreateInstance("test.UserControl1");
            UserControl usl = (UserControl)obj;
            usl.Width = this.Width;
            usl.Height = this.Height;
            this.Controls.Add(usl);



            //object obj = GetInstanceByName("tabwin." + MoudelCommon.moudelName);
            //UserControl usl = (UserControl)obj;
            //this.Controls.Add(usl);
        }

        private object GetInstanceByFile(string filename, string typename)
        {
            object obj;

            try
            {
                obj = Assembly.Load(filename).CreateInstance(typename);
            }

            catch (Exception e)
            {
                throw new Exception("动态创建实例失败 " + filename, e);
            }
            return obj;
        }

        private object GetInstanceByName(string className)
        {
            object obj;

            try
            {
                obj = Activator.CreateInstance(Type.GetType(className));
            }

            catch (Exception e)
            {
                throw new Exception("动态创建实例失败 " + className, e);
            }
            return obj;
        }
    }
}
